package com.neuedu.cockpit.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.neuedu.cockpit.domain.HmFeedback;
import com.neuedu.cockpit.service.IHmFeedbackService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.neuedu.common.annotation.Log;
import com.neuedu.common.core.controller.BaseController;
import com.neuedu.common.core.domain.AjaxResult;
import com.neuedu.common.enums.BusinessType;
import com.neuedu.common.utils.poi.ExcelUtil;
import com.neuedu.common.core.page.TableDataInfo;

/**
 * 意见反馈Controller
 * 
 * @author neuedu
 * @date 2024-04-25
 */
@RestController
@RequestMapping("/cockpit/feedback")
public class HmFeedbackController extends BaseController
{
    @Autowired
    private IHmFeedbackService hmFeedbackService;

    /**
     * 查询意见反馈列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HmFeedback hmFeedback)
    {
        startPage();
        List<HmFeedback> list = hmFeedbackService.selectHmFeedbackList(hmFeedback);
        return getDataTable(list);
    }

    /**
     * 获取意见反馈详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(hmFeedbackService.selectHmFeedbackById(id));
    }

    /**
     * 新增意见反馈
     */
    @Log(title = "意见反馈", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody HmFeedback hmFeedback)
    {
        return toAjax(hmFeedbackService.insertHmFeedback(hmFeedback));
    }

    /**
     * 修改意见反馈
     */
    @Log(title = "意见反馈", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody HmFeedback hmFeedback)
    {
        return toAjax(hmFeedbackService.updateHmFeedback(hmFeedback));
    }

    /**
     * 修改反馈读取状态
     */
    @Log(title = "意见反馈", businessType = BusinessType.UPDATE)
    @PostMapping("/editReplyRead")
    public AjaxResult editReplyRead(@RequestBody HmFeedback hmFeedback)
    {
        return toAjax(hmFeedbackService.updateReplyRead(hmFeedback));
    }

    /**
     * 修改意见反馈已读状态
     */
    @Log(title = "意见反馈已读状态变更", businessType = BusinessType.UPDATE)
    @PostMapping("/feedbackStatus")
    public AjaxResult editStatus(@RequestBody HmFeedback hmFeedback)
    {
        return toAjax(hmFeedbackService.updateHmFeedbackStatus(hmFeedback));
    }

    /**
     * 删除意见反馈
     */
    @Log(title = "意见反馈", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hmFeedbackService.deleteHmFeedbackByIds(ids));
    }

    /**
     * APP接口：获取反馈信息
     */
    @GetMapping(value = "/backList")
    public AjaxResult feedbackList() {
        Long userId = getLoginUser().getUser().getUserId();
        return AjaxResult.success(hmFeedbackService.selectHmFeedbackListByUserId(userId));
    }
}
